﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;

namespace University.Workshop.Presenters.Users
{
    public class PresenterModifyUserPassword
    {
        IModifyUserPasswordView view;
        Model.User userToModify = new Model.User();

        public PresenterModifyUserPassword(IModifyUserPasswordView view, Model.User user)
        {
            this.view = view;
            this.userToModify.Login = user.Login != null ? user.Login : string.Empty;
            this.userToModify.Password = user.Password != null ? user.Password : string.Empty;
            //Agregar el login+
            //Agregar al usuario como true
            this.userToModify.UserId = user.UserId;
        }

        public void UpdateViewData()
        {
            view.Login = userToModify.Login;
        }

        public bool UpdatePerson()
        {
            try
            {
                Model.User u = new Model.User() { UserId = userToModify.UserId, Password = view.NewPassword, RetryPassword = view.RetryPassword, OldPassword = view.OldPassword };
                ManagerUser.UpdateUserPassword(u);
                return true;
            }
            catch (Exception ex)
            {
                view.ErrorMessage(string.Format(ex.Message, "Cambiar contraseña"));
                return false;
            }



        }
    }
}
